package com.itheima.service.impl;

import com.itheima.dao.IStudentDao;
import com.itheima.dao.impl.StudentDaoImpl;
import com.itheima.domain.Student;
import com.itheima.factory.Factory;
import com.itheima.service.IStudentService;

import java.util.ArrayList;

public class StudentServiceImpl implements IStudentService {
    private IStudentDao dao = Factory.getStudentDao();

    @Override
    public void addStudent(Student student) {
        dao.addStudent(student);

    }

    @Override
    public void deleteStudent(String sid) {
        dao.deleteStudent(sid);
    }

    @Override
    public void updateStudent(String sid, Student newStu) {
        dao.updateStudent(sid, newStu);
    }

    @Override
    public ArrayList<Student> findAllStudents() {
        return dao.findAllStudents();
    }

    @Override
    public boolean isExists(String sid) {
        ArrayList<Student> list = dao.findAllStudents();
        for (int i = 0; i < list.size(); i++) {
            Student student = list.get(i);
            if(student!=null&&student.getSid().equals(sid)){
                return true;
            }
        }
        return false;
    }
}
